<template>
  <view>
    <view class="info">
      <image :src="v.image" mode="widthFix" style="width: 100%;"></image>
      <view>{{v.title}}</view>
      <view>{{v.desc}}</view>
      <view style="color: red;">￥：{{v.price}}</view>
    </view>
    <button type="primary" @click="handleAdd">加入购物车</button>
    <button type="primary" @click="toCar">进入购物车</button>
  </view>
</template>

<script>
  import { mapMutations } from 'vuex'
  export default {
    onLoad({
      id
    }) {
      this.id = id;

      uni.request({
        url: 'http://localhost:3000/list/' + id
      }).then(resp => {
        this.v = resp.data
      })
    },
    data() {
      return {
        id: "",
        v: {}
      };
    },
    methods: {
      ...mapMutations('car', ['addCar']),
      handleAdd() {
        this.addCar({
          ...this.v,
          count: 1,
          state: true
        })
      },
      toCar() {
        uni.switchTab({
          url: '/pages/car/car'
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
